package bb.lanxing.lib.devices.ble;

import android.util.Log;
import com.umeng.socialize.common.SocializeConstants;
import bb.lanxing.common.config.Constants;
import bb.lanxing.lib.devices.base.DeviceContext;
import bb.lanxing.lib.devices.sprint.utils.SprintFileHelper;
import java.io.File;
//import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;
/* compiled from: XOSSFGFileHelper.kt */

public final class XOSSFGFileHelper {
    public static final XOSSFGFileHelper INSTANCE = new XOSSFGFileHelper();

    private XOSSFGFileHelper() {
    }

    public String getWorkRootDir(String deviceName) {
        Intrinsics.checkNotNullParameter(deviceName, "deviceName");
        String str = DeviceContext.getRootDir(0) + File.separator + StringsKt.trim(deviceName);
        File file = new File(str);
        if (!file.exists() && !file.mkdirs()) {
            Log.w("XOSSFGFileHelper", "make WorkDir: " + str);
        }
        return str;
    }

    public String getFileFolderPath(String parentDir, FILE fileType) {
        String str;
        Intrinsics.checkNotNullParameter(parentDir, "parentDir");
        Intrinsics.checkNotNullParameter(fileType, "fileType");
        File file = new File(parentDir);
        if (!file.exists() && !file.mkdirs()) {
            Log.w("XOSSFGFileHelper", "make WorkDir: " + parentDir);
        }
        StringBuilder sb = new StringBuilder();
        sb.append(parentDir);
        str = switch (fileType) {
            case WORKOUT, WORKOUT_2 -> "/Workouts";
            case ROUTE_BOOKS -> "/Routebooks";
            case MAPS -> "/Maps";
            case SETTING, SETTING_2, USERPROFILE, PANEL, GEAR_PROFILE, NOTIFICATION -> "/Settings";
            case TRAINING -> "/Trainings";
            case SEGMENT -> "/Segments";
            case LOG -> "/Log";
            case GNSS -> "/Ephemeris";
            default -> "";
        };
        sb.append(str);
        String sb2 = sb.toString();
        File file2 = new File(sb2);
        if (!file2.exists() && !file2.mkdirs()) {
            Log.w("XOSSFGFileHelper", "make WorkDir: " + sb2);
        }
        return sb2;
    }

    public enum FILE {
        WORKOUT(SprintFileHelper.FILE_LIST),
        WORKOUT_2("workouts.json"),
        SETTING(SprintFileHelper.SETTINGS_FILE_NAME),
        SETTING_2("settings.json"),
        ROUTE_BOOKS(SprintFileHelper.NAV_FILE_NAME),
        MAPS("maps.json"),
        USERPROFILE("user_profile.json"),
        GEAR_PROFILE("gear_profile.json"),
        PANEL("panels.json"),
        TRAINING("training.json"),
        NOTIFICATION("notification.json"),
        GNSS("offline.gnss"),
        SEGMENT("segment.json"),
        LOG("crash.log");
        
        public static final Companion Companion = new Companion(null);
        private final String fileName;

        FILE(String str) {
            this.fileName = str;
        }

        public final String getFileName() {
            return this.fileName;
        }


        public static final class Companion {
            public Companion(DefaultConstructorMarker defaultConstructorMarker) {
                this();
            }

            private Companion() {
            }

            public FILE from(String s) {
                FILE[] values;
                Intrinsics.checkNotNullParameter(s, "s");
                for (FILE file : FILE.values()) {
                    if (StringsKt.equals(file.getFileName(), StringsKt.trim(s).toString(), true)) {
                        return file;
                    }
                }
                return null;
            }

            public boolean isTargetFile(String fileName, FILE targetFile) {
                Intrinsics.checkNotNullParameter(fileName, "fileName");
                Intrinsics.checkNotNullParameter(targetFile, "targetFile");
                FILE from = from(fileName);
                return Intrinsics.areEqual(from != null ? from.getFileName() : null, targetFile.getFileName());
            }
        }
    }

    public enum FILETYPE {
        TXT(SocializeConstants.KEY_TEXT),
        ROUTE("ro"),
        FIT(Constants.FIT_DIR),
        MAP("map"),
        JSON("json"),
        GNSS("gnss"),
        LOG("log");
        
        public static final Companion Companion = new Companion(null);
        public static final String DOT = ".";
        private final String suffix;

        FILETYPE(String str) {
            this.suffix = str;
        }

        public final String getSuffix() {
            return this.suffix;
        }


        public static final class Companion {
            public Companion(DefaultConstructorMarker defaultConstructorMarker) {
                this();
            }

            private Companion() {
            }

            public FILETYPE from(String s) {
                FILETYPE[] values;
//                Intrinsics.checkNotNullParameter(s, "s");
                for (FILETYPE filetype : FILETYPE.values()) {
                    String lowerCase = StringsKt.trim(s).toString().toLowerCase();
//                    Intrinsics.checkNotNullExpressionValue(lowerCase, "this as java.lang.String).toLowerCase()");
                    if (StringsKt.endsWith(lowerCase, filetype.getSuffix(), false/*, 2, (Object) null*/)) {
//                    if (lowerCase.endsWith(filetype.getSuffix())) {
                        return filetype;
                    }
                }
                return null;
            }

            public boolean isTargetFileType(String suffix, FILETYPE targetFileType) {
//                Intrinsics.checkNotNullParameter(suffix, "suffix");
//                Intrinsics.checkNotNullParameter(targetFileType, "targetFileType");
                FILETYPE from = from(suffix);
                return Intrinsics.areEqual(from != null ? from.getSuffix() : null, targetFileType.getSuffix());
            }
        }
    }
}
